<!-- -->
<template>
  <div class="public">
    <el-card>
      <SearchTable :page="searchPage" @search="search" v-model="searchData" />

      <div class="tip">
        <dl v-for="item in list" :key="item.id">
          <dt>
            <img v-lazy="item.img" alt />
          </dt>
          <dd>
            <span>{{item.title}}</span>
            <p>
              <span>{{item.name}}</span>
              <span>{{item.date}}</span>
            </p>
            <div v-if="item.live==='0'" class="live-info">
              <p>进入直播</p>
              <p>
                <el-switch v-model="value1">开启</el-switch>
              </p>
            </div>

            <div v-if="item.live==='1'" class="live-info">
              <p>回看</p>
              <p>删除</p>
            </div>

            <div v-if="item.live==='2'" class="live-info">
              <p>进入直播</p>
              <p @click="del(item.id)">删除</p>
            </div>
          </dd>
        </dl>
      </div>
      <div class="page">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="total*1"
          :current-page.sync="obj.current"
          @current-change="changePage"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getLiveList, searchLiveList, delLiveList } from "@/api";
import SearchTable from "@/components/SearchTable";
export default {
  // import引入到组件需要注入到对象中才能使用
  components: { SearchTable },
  data() {
    // 这里存放数据
    return {
      searchPage: [
        {
          lable: "直播状态",
          type: "select",
          value: "status",
          options: [
            {
              value: "已开团",
              label: "已开团"
            },
            {
              value: "未开团",
              label: "未开团"
            }
          ]
        },
        {
          lable: "经纪人搜索",
          type: "input",
          value: "value",
          placeholder: "请搜索经纪人/ID"
        }
      ],
      list: [],
      value1: true,
      obj: {
        size: 10,
        current: 1
      },
      total: 0,
      value: "",
      searchData: {}
    };
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监听data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // 获取输入框输入的内容
    search(data) {
      this.value = data.value;
      console.log(data.status);
      // 搜索直播的
      searchLiveList({ value: this.value }).then(res => {
        this.list = res.data;
      });
    },
    // 获取直播数据
    getList() {
      getLiveList({
        size: this.obj.size,
        current: this.obj.current
      }).then(res => {
        this.list = res.data;
        this.total = res.total;
      });
    },
    // 分页
    changePage(e) {
      this.obj.current = e;
      this.getList();
    },
    del(id) {
      delLiveList({ id }).then(res => {
        this.getList();
      });
    }
  },
  //生命周期 - 创建完成 (可以访问当前this实例)
  created() {
    this.getList();
  },
  //生命周期 - 挂载完成 (可以访问DOM元素)
  mounted() {}
};
</script> 

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style lang='scss'  scoped>
.public {
  padding: 20px 38px;
}
.tip {
  width: 100%;
  height: auto;
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;

  dl {
    width: 25%;
    height: auto;
    padding: 10px;
    dt {
      img {
        width: 180px;
        height: 120px;
      }
      img[lazy="loading"] {
        display: block;
        width: 180px !important;
        height: 120px !important;
        margin: 0 auto;
      }
    }
    dd {
      width: 100%;
      height: auto;
      font-size: 14px;
      .live-info {
        display: flex;
        p {
          margin-right: 20px;
        }
      }
    }
  }
}
</style>

